<template>
    <div class="proportion-tab">
        <p
          v-for="(item, index) in timeList"
          :key="index + 'a'"
          @click="timeTabFn(item, index)"
          :style="{width: width + 'px'}"
          :class="activeIndex == index ? 'proportion-tab-active' : ''">
            {{ item.title }}
        </p>
    </div>
</template>

<script>
export default {
    props: {
        timeList: {
            type: Array,
            default: () => {
                return [
                    {
                        title: '同比',
                        value: 1,
                    },
                    {
                        title: '环比',
                        value: 2,
                    },
                ]
            }
        },

        width: {
            type: Number,
            default: 60,
        }
    },
    data() {
        return {
            activeIndex: 0
        }
    },

    methods: {
        timeTabFn(value, index) {
            this.activeIndex = index
            this.$emit('timeReturnFn', value)
        }
    }
}
</script>

<style lang="less" scoped>
.proportion-tab {
    display: flex;
    align-items: center;

    p {
        min-width: 5rem;
        max-width: 7rem;
        height: 2rem;
        background: url('../../assets/images/zhangzi/zhifazhuanti/nactive.png') no-repeat;
        background-size: 100% 100%;
        font-size: 1.2rem;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #FFFFFF;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        margin-right: 0.5rem;
        cursor: pointer;

        &:last-child {
            margin: 0;
        }
    }

    .proportion-tab-active {
        background: url('../../assets/images/zhangzi/zhifazhuanti/active.png') no-repeat;
        background-size: 100% 100%;
    }
}
</style>